<template>
    <div class="zh-comment-course">					
        <nav-header></nav-header>
        <div class="zh-table">
            <div class="zh-table-open clear">
                <div class="zh-open-left fl">
                    <div class="open-width">
                        <el-select v-model="eva_status"  filterable placeholder="请选择">
                            <el-option
                                v-for="item in statusOption"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <div class="open-width">
                        <el-input v-model="keyword" placeholder="请输入活动名搜索" @keyup.enter.native="searchFunc"></el-input>
                    </div>
                    <el-button type="primary" @click="searchFunc">搜索</el-button>
                    <el-button type="primary" @click="reset">重置</el-button>
                </div>
                <div class="zh-open-right fr">
                </div>
            </div>
            <div class="zh-table-contents">
                <el-table
                    :data="listData"
                    border
                    max-height="600"
                    style="width: 100%">
                    <el-table-column
                        type="index"
                        :index="typeIndex"
                        label="序号"
                        align="center"
                        show-overflow-tooltip
                        width="50"
                        >
                    </el-table-column>
                    <el-table-column
                        prop="name"
                        label="活动主题"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column>
                    <el-table-column
                        prop="user_name"
                        label="发起人"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column>
                    <el-table-column
                        prop="start_time"
                        label="开始时间"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column>
                    <el-table-column
                        prop="end_time"
                        label="结束时间"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column>
                    <el-table-column
                        prop="_status"
                        label="活动状态"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column>
                    <el-table-column
                        prop=""
                        label="当前得分"
                        align="center"
                        show-overflow-tooltip
                        >
                        <template slot-scope="scope">
                            <template v-if="scope.row.total_score != null ">
                                <font color="red">{{scope.row.total_average_score}}</font>/{{scope.row.total_score}}
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="5"
                        label="操作"
                        align="center"
                        width="100"
                        show-overflow-tooltip
                        >
                        <template slot-scope="scope">
                            <!-- <a style="color:#409EFF" :href="BASE_URL+'/netteach/details?id='+scope.row.id" target="_blank" type="text">查看</a> -->
                            <el-button @click="toNetteach(scope.row)" type="text" >查看</el-button>
                            <el-button @click="delete_confirm(scope.row)" type="text" class="delete-button">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="table-pagination" v-show="total_number > 10">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="listParam.page_index"
                        :page-sizes="[10, 20, 30, 40, 50, 100]"
                        :page-size="listParam.page_size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total_number">
                    </el-pagination>
                    <div class="pagination-button">
                        <el-button 
                            @click="getList"
                            type="primary" icon="el-icon-refresh" 
                            circle title="刷新数据" size="mini" >
                        </el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                listData:[],
                    listParam:{
                        eva_status:0,
                    keyword: '',
                    page_index:1,
                    page_size:10,
                        },
                        eva_status:0,
                keyword: '',
                total_number:0,
                statusOption:[
                    {
                        value: 0,
                        label: '全部状态'
                    },
                    {
                        value: 1,
                        label: '未开始'
                    },
                    {
                        value: 2,
                        label: '进行中'
                    },
                        {
                        value: 3,
                        label: '已结束'
                    },
                ],
            }
        },
        created(){
            this.getList();
        },
        methods: {
            toNetteach(obj) {
                let host_addr = sessionStorage.getItem('host_addr');
                let host = host_addr.split('://')[1];
                let token = sessionStorage.getItem('redirect_params');
                let url = `${host_addr}${token}&host=${host}&routerUrl=/netteach/details&id=${obj.id}&CheckSchoolAppCode=${sessionStorage.getItem('CheckSchoolAppCode')}`
                window.open(url)
            },
            searchFunc(){
                this.listParam.eva_status = this.eva_status;
                this.listParam.keyword = this.keyword;
                this.listParam.page_index = 1;
                this.getList();
            },
            reset() {
                this.eva_status = 0;
                this.keyword = '';
                this.listParam = {
                    eva_status:0,
                keyword: '',
                page_index:1,
                page_size:10,
                }
                this.getList();
            },
            // 序号
            typeIndex(index) {
                return index + (this.listParam.page_index - 1) * this.listParam.page_size + 1;
            },
            getList(){
                let success = (data=>{
                    this.listData = data.data.data;
                    this.total_number = data.data.data_sum;
                })
                //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
                this.$ajax.get('api/network/eva_list',{params: this.listParam,func:{success:success}})
            },
            delete_confirm(obj){
                let yes = ( data => {
                    this.delete(obj.id,0);
                })
                let cancel = ( data => {})
                this.e_confirm({yes:yes,cancel:cancel,txt:'确定将 '+obj.name+' 删除吗？'});

            },
            delete(id,status){
                let success = ( data => {
                    this.$message.success(data.msg);

                    if (this.listData.length - this.rowLen === 0) {
                        if (this.listParam.page_index > 1) {
                            this.listParam.page_index-- ;
                        } else {
                            this.listParam.page_index = 1;
                        }
                    }

                    this.getList();
                });
                this.$ajax.delete('api/network/eva_list',{params:{id:id,status:status},func:{success:success}})
            },
                handleSizeChange(val) {
                this.listParam.page_index = 1;
                this.listParam.page_size = val;
                this.getList()
            },
            handleCurrentChange(val) {
                this.listParam.page_index = val;
                this.getList();
            },
        },
    }
</script>
<style lang="scss">
	.zh-comment-course {
		.el-table__body-wrapper table tbody {
			td:nth-child(8) {
				padding: 0;
			}
		}
	}
</style>